#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#pragma "E:/SWTSoft/SWTLib/OpenCV/lib/opencv_world300d.dll"
using namespace cv;
using namespace std;

/// Function header
//void thresh_callback(int, void* );
void testFindCounter();
/** @function main */
int main( int argc, char** argv )
{
    testFindCounter();
    waitKey(0);
    return(0);
}
void testFindCounter()
{
    /// Load source image and convert it to gray
    Mat src=imread("D:\\SWT_OUT\\SWTCV\\das.jpg",1);//cv::cvarrToMat(cvLoadImage("D:\\SWT_OUT\\SWTCV\\das.jpg"));
    if(!(src).data)
        return;

    // the first command-line parameter must be a filename of the binary
    // (black-n-white) image
    Mat dst = Mat::zeros(src.rows, src.cols, CV_8UC3);
    src = src > 1;
    cvtColor( src, src, CV_BGR2GRAY );
    namedWindow( "Source", 1 );
    imshow( "Source", src );
    vector<vector<Point>> contours;
    vector<Vec4i> hierarchy;

    findContours( src, contours, hierarchy,
                  RETR_CCOMP, CHAIN_APPROX_SIMPLE );
    // iterate through all the top-level contours,
    // draw each connected component with its own random color
    int idx = 0;
    for( ; idx >= 0; idx = hierarchy[idx][0] )
    {
        Scalar color( 255,255, 255 );
        drawContours( dst, contours, idx, color, FILLED, 8, hierarchy );
    }
    namedWindow( "Components", 1 );
    imshow( "Components", dst );
    waitKey(0);
}

